<template>
    <div class="padding20">
        <!--面包屑导航区域-->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>订单管理</el-breadcrumb-item>
            <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>

        <!--卡片视图-->
        <el-card>
            <!--搜索组件-->
            <el-row>
                <el-col :span="8">
                    <el-input placeholder="请输入内容" 
                        v-model="queryInfo.query"
                        clearable
                        @clear="getOrdersList"
                        @keyup.enter.native="getOrdersList">
                        <el-button slot="append" icon="el-icon-search" @click="getOrdersList"></el-button>
                    </el-input>
                </el-col>
                
            </el-row>

            <!--表格-->
            <el-table :data="ordersList" border stripe>
                <el-table-column type="index" label="#"></el-table-column>
                <el-table-column label="订单名称" prop="order_number"></el-table-column>
                <el-table-column label="订单价格" prop="order_price" width="100px"></el-table-column>
                <el-table-column label="是否付款" width="100px">
                    <template slot-scope="scope">
                        <el-tag type="danger" v-if="scope.row.pay_status==='0'">未付款</el-tag>
                        <el-tag type="success" v-else>已付款</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="是否发货" prop="is_send" width="100px"></el-table-column>
                <el-table-column label="下单时间" width="200px">
                    <template slot-scope="scope">
                        {{scope.row.create_time | timeStampFormat }}
                    </template>
                </el-table-column>
                <el-table-column label="操作" prop="goods_weight" width="200px">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" icon="el-icon-edit" @click="showEditAddressBox(scope.row)"></el-button>
                        <el-button type="success"  size="mini" icon="el-icon-location" @click="showProgressDialog(scope.row)"></el-button>
                    </template>
                </el-table-column>
            </el-table>

            <!--分页组件-->
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="queryInfo.pagenum"
                :page-sizes="[2,5,10]"
                :page-size="queryInfo.pagesize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="ordersListTotal">
            </el-pagination>
        </el-card>

        <!--修改地址 对话框-->
        <el-dialog
            title="修改地址"
            :visible.sync="showEditAddressDialogVisible"
            width="50%"
            @close="closeEditDialog">
            <!--内容主体区-->
            <el-form :model="editAddressFrom" :rules="editAddressRules" ref="editAddressFromRef" label-width="100px">
                <el-form-item prop="address1" label="省市区/县">
                    <el-cascader
                        v-model="editAddressFrom.address1"
                        :options="cityData"
                        :props="slectedCateProps"
                        @change="handleChange"
                        clearable
                        >
                    </el-cascader>
                </el-form-item>
                <el-form-item prop="address2" label="详细地址">
                    <el-input v-model="editAddressFrom.address2"></el-input>
                </el-form-item>
            </el-form>
            <!--底部按钮区-->
            <span slot="footer">
                <el-button @click="closeEditDialog">取 消</el-button>
                <el-button type="primary" @click="handleEditDialogPost">确 定</el-button>
            </span>
        </el-dialog>

        <!--物流进度对话框-->
        <el-dialog
            title="物流详细"
            :visible.sync="showProgressDialogVisible"
            width="50%">
            <!--内容主体区-->
            <el-timeline :reverse="true">
                <el-timeline-item
                    v-for="(item, index) in kuaidi.data"
                    :key="index"
                    :timestamp="item.time">
                    {{item.context}}
                </el-timeline-item>
            </el-timeline>
        </el-dialog>
    </div>
</template>

<script>
import {handleGetOrderssList,handleGetOrderProgress} from '@/request/order'
import cityData from './cityData'
import kuaidi from './kuaidi'
export default {
    props: {

    },
    components: {

    },
    data() {
        return {
            cityData,
            kuaidi,
            queryInfo:{
                query:'',
                pagenum: 1,
                pagesize: 5
            },
            ordersList:[],
            ordersListTotal:0,
            showEditAddressDialogVisible:false, //修改地址dialog开关
            editAddressFrom:{
                address1:[],
                address2:''
            },
            editAddressRules:{
                address1: [
                    { required: true, message: '请选择区域', trigger: 'blur' }
                ],
                address2: [
                    { required: true, message: '请输入详细地址', trigger: 'blur' },
                    { min: 1, max: 20, message: '长度在 2 到 10 个字符', trigger: 'blur' }
                ],
            },
            slectedCateProps:{    //级联选择器配置对象
                value: 'value',
                label: 'label',
                children: 'children'
            },
            showProgressDialogVisible:false
        };
    },
    computed: {

    },
    created() {
        this.getOrdersList()
    },
    mounted() {

    },
    watch: {

    },
    methods: {
        /*
            打开物流信息对话框
        */
        showProgressDialog(row){
            this.showProgressDialogVisible = true
            console.log(row,this.kuaidi)
            // //目前接口没有真实数据  只提供一个测试数据！  orderID  1106975712662
            // let orderId = '804909574412544580'
            // handleGetOrderProgress(orderId)
            // .then(res=>{
            //     console.log(res)
            // })

            //因接口数据不可用，只能导入假数据测试了
            if(this.kuaidi.meta.status!==200){
                return this.$message.error('获取快递失败')
            }
        },
        getOrdersList(){
            handleGetOrderssList(this.queryInfo)
            .then(res=>{
                if(res.meta.status!==200){
                    return this.$message.error('获取订单列表失败')
                }else{
                    this.ordersList = res.data.goods
                    this.ordersListTotal = res.data.total
                }
            })
        },
        /*
            监听pageSize改变
        */
        handleSizeChange(newSize){
            this.queryInfo.pagesize = newSize
            this.getOrdersList()
        },
        /*
            监听页码值page改变
        */
        handleCurrentChange(newPage){
            this.queryInfo.pagenum = newPage
            this.getOrdersList()
        },
        /*
            打开修改地址dialog
        */
        showEditAddressBox(row){
            console.log(row)
            this.showEditAddressDialogVisible = true
        },
        closeEditDialog(){
            this.$refs.editAddressFromRef.resetFields()
            this.editFrom = {
                address1:[],
                address2:''
            }
            this.showEditAddressDialogVisible = false
        },
        /*
            级联选择器发生改变
        */
        handleChange(){

        },
        /*
            提交修改后地址
        */
       handleEditDialogPost(){

       }
    },
};
</script>

<style scoped lang="less">

</style>
